// pages/question/jubao.js
var Crypto = require('../../utils/cryptojs/cryptojs.js').Crypto;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jubao:[
      { name: "欺诈"},
      { name: "色情" },
      { name: "政治谣言" },
      { name: "常识性谣言" },
      { name: "诱导分享" },
      { name: "恶意营销" },
      { name: "隐私信息收集" },
      { name: "其他侵权类（冒名，诽谤，抄袭）" },
    ],
    current:-1,
    jubaoStyle:'',
    tell:'',
    chat:'',
  },
  jubaoLabel:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var style = e.currentTarget.dataset.style;
    that.setData({
      current:index,
      jubaoStyle:style,
    })

  },
  tell:function(e){
    var that = this;
    var tell = e.detail.value;
    console.log(tell);
    that.setData({
      tell:tell
    })
  },
  chat:function(e){
    var that = this;
    var chat = e.detail.value;
    that.setData({
      chat: chat
    })
  },
  fromSubmit: function (e) {
    var that = this;
    var formId = e.detail.formId
    app.formId(formId);
    if (that.data.jubaoStyle==''){
      app.showInfo("请选择举报类型")
    }else{
      that.report();
    }
    
  }, 
  report:function(){
    var that = this;
    wx.getStorage({
      key: 'token',
      success: function(res) {
        var token= res.data;
        var url = app.globalData.localApi + "/user/report";
        var timestamp = app.timestamp();
        var sign = Crypto.MD5(app.sign(url, token, timestamp));
        wx.request({
          url: url,
          method:"POST",
          data:{
            url:app.urlStr(url),
            timestamp:timestamp,
            token:token,
            sign:sign,
            report: that.data.jubaoStyle,
            telephone:that.data.tell,
            wxnumber:that.data.chat
          },
          success:function(res){
            if(res.data.code==0){
              wx.showModal({
                title: '提示信息',
                content: '举报成功！',
                showCancel:false,
                success:function(res){
                  if(res.confirm){
                    wx.navigateBack({
                      delta: 1,
                    })
                  }
                }
              })

            }
          }

        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})